package com.tanhua.server.controller;

import com.tanhua.model.vo.NearUserVo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.TodayBest;
import com.tanhua.server.service.TanhuaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.query.Term;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.security.PublicKey;
import java.util.List;
import java.util.Map;

/**
 * @program: tanhua
 * @description:
 * @author: MR.peng
 * @create: 2022-03-11 13:25
 **/

@RestController
@RequestMapping("/tanhua")
public class TanhuaController {

    @Autowired
    private TanhuaService tanhuaService;

    /*
    * 首页：今日佳人
    *   业务：查询推荐用户，查询score最高的用户即可
    *    接口路径：GET /todayBest
    *    返回值：
    *
    *
    * */

    @GetMapping("/todayBest")
        public ResponseEntity<TodayBest> todayBest(){
        //1.获取参数
        //2.调用service
        TodayBest vo = tanhuaService.todayBEst();
        return ResponseEntity.ok(vo);

    }

    /*
    * 查询推荐列表
    * GET  /tanhua/recommendation
    * Query 参数
    *       page,pageSize
    * 返回值：
    *   PageResult --
    * */

    @GetMapping("/recommendation")
    public ResponseEntity recommendation(
           @RequestParam(defaultValue = "1") Integer page,
           @RequestParam(defaultValue = "10") Integer pageSize
    ){
        PageResult vo = tanhuaService.recommendation(page, pageSize);
        return ResponseEntity.ok(vo);
    }

    /*
    * 佳人信息
    *   请求路径：GET /:id/personalInfo
    *   返回值：todayBestVo对象
    *
    * */
    @GetMapping("/{userId}/personalInfo")
    public  ResponseEntity personalInfo(@PathVariable("userId") Long userId){
       TodayBest vo =  tanhuaService.personalInfo(userId);
       return ResponseEntity.ok(vo);
    }

    /*
    * 查看用户的陌生人信息
    *   接口路径：POST /strangerQuestions
    *   参数名称：query userId
    * 返回值：陌生人问题(String)
    *
    * */
    @GetMapping("/strangerQuestions")
    public ResponseEntity strangerQuestions(Long userId){
        String txt = tanhuaService.strangerQuestions(userId);
        return ResponseEntity.ok(txt);

    }

    /*
    * 回复陌生人问题
    *   接口路径： POST /strangerQuestions
    *   参数:Body  userId(对方用户的id),reply（回复内容）
    *   返回值 :空
    *
    * */
    @PostMapping("/strangerQuestions")
    public ResponseEntity reply(@RequestBody Map map){
        //1.获取参数
        String reply = map.get("reply").toString();
        String temp = map.get("userId").toString();
        Long userId = Long.valueOf(temp);
        //2.service
        tanhuaService.reply(userId,reply);
        return ResponseEntity.ok(null);
    }

    /*
    * 搜索附近的人：
    *      GET  /search
    *      参数：Query gender,distance
    *      返回值 List<NearUserVo>
    * */
    @GetMapping("/search")
    public ResponseEntity search(String gender,String distance){
        List<NearUserVo> vos =  tanhuaService.search(gender,distance);
        return ResponseEntity.ok(vos);
    }
    /*
     *接口名称：探花-左滑右滑
     *接口路径：GET   /tanhua/cards
     *请求参数 无
     *返回数据 无
     * */
    @GetMapping("/cards")
    public ResponseEntity cards() {
        List<TodayBest> list  = tanhuaService.cards();
        return ResponseEntity.ok(list);

    }

    /*
    *接口名称：探花-不喜欢
    *接口路径：GET   /tanhua/:id/unlove
    *请求参数
      路径参数：id 用户ID
    *返回数据：无
    * */
    @GetMapping("/{id}/unlove")
    public ResponseEntity unlove(@PathVariable("id") Long userId) {
        tanhuaService.unlove(userId);
        return ResponseEntity.ok(null);
    }

    /*
     *接口名称：探花-喜欢
     *接口路径：GET   /tanhua/:id/love
     *请求参数
     *路径参数：id 用户ID
     *返回数据：无
     * */

    @GetMapping("/{id}/love")
    public ResponseEntity love(@PathVariable("id") Long userId) {
        tanhuaService.love(userId);
        return ResponseEntity.ok(null);
    }
}
